package com.abe.libquick.main.video.player;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.abe.libquick.main.video.record.VideoRecordActivity;
import com.abe.libquick.main.video.record.VideoRecordPreviewActivity;
import com.abe.libquick.utils.quick.EmptyUtils;

public class VideoRecordHelper {
    public static final String VIDEO_PATH = "videoPath";
    public static final String VIDEO_MAX_DURATION = "videoMaxDuration";
    public static final String VIDEO_CONFIRM = "videoConfirm";

    /**
     * 录制直接返回路径
     *
     * @param maxDuration 最大录制时长（0-60s）
     */
    public static void open(Activity activity, int requestCode, int... maxDuration) {
        if (EmptyUtils.isEmpty(activity)) return;
        Intent intent = new Intent(activity, VideoRecordActivity.class);
        if (maxDuration.length > 0) {
            int duration = maxDuration[0];
            if (duration < 0 || duration > 60000) return;
            Bundle bundle = new Bundle();
            bundle.putInt(VIDEO_MAX_DURATION, duration);
            intent.putExtras(bundle);
        }
        activity.startActivityForResult(intent, requestCode);
    }

    /**
     * 录制直接预览
     *
     * @param maxDuration 最大录制时长（0-60s）
     */
    public static void recordAndPreview(Activity activity, int requestCode, int... maxDuration) {
        if (EmptyUtils.isEmpty(activity)) return;
        Intent intent = new Intent(activity, VideoRecordPreviewActivity.class);
        if (maxDuration.length > 0) {
            int duration = maxDuration[0];
            if (duration < 0 || duration > 60000) return;
            Bundle bundle = new Bundle();
            bundle.putInt(VIDEO_MAX_DURATION, duration);
            intent.putExtras(bundle);
        }
        activity.startActivityForResult(intent, requestCode);
    }

    public static void show(Activity activity, String path) {
        if (EmptyUtils.isEmpty(activity) || EmptyUtils.isEmpty(path)) return;
        Intent intent = new Intent(activity, VideoPlayerActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString(VIDEO_PATH, path);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }
}